
/*
 * @Author: dxzheng
 * @Date: 2020-06-18 19:46:55
 * @LastEditTime: 2020-06-22 21:00:53
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \n2020061802\app.js
 */
const express = require('express');
const expressStatic = require('express-static');
const db = require('./utils/db/dbconnect');
const bodyPaser = require('body-parser');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');
const sildeImgRouter = require('./routes/sildeImgRouter');
const userRouter = require('./routes/userRouter');
const viewRouter = require('./routes/viewRouter');
const wearRouter = require('./routes/wearImgRouter');


var app = express();

app.listen(8080, function (err) {
    if (!err) {
        console.log('app is running...');
    }
})

db.dbConnect('mongodb://127.0.0.1/lnsf2017');

app.use(bodyPaser.urlencoded({
    extend: true
}))

var key = [];
for (var i = 0; i < 100; i++) {
    key.push('16563^&676^&%^%' + Math.random(10000));
}
app.use(cookieParser());
app.use(cookieSession({
    keys: key,
    name: 'user-message',
    maxAge: 20 * 60 * 1000
}))


app.use('/slide', sildeImgRouter.router);
app.use('/user', userRouter.router);
app.use('/views', viewRouter.router);
app.use('/wear', wearRouter.router);

app.use('/', function (req, res, next) {
    var url = req.url;
    if (url.indexOf('/') == 0 && url.length > 1) {  //显示初页面
        next();
    } else {
        res.sendFile(__dirname + '/www/index.html', function (err) {
            if (err) {
                console.log('error!');
            }
        });
    }
})

app.use(expressStatic('./www'));





















